<?php
include_once("config/usergroup.php");
//====================================
$id=!empty($_GET["id"])?$_GET["id"]:NULL;
$key=!empty($_GET["key"])?trim($_GET["key"]):NULL;
$trade_type=!empty($_GET["trade_type"])?$_GET["trade_type"]:NULL;
$firstRow=!empty($_GET["firstRow"])?$_GET["firstRow"]:NULL;
$totalRows=!empty($_GET["totalRows"])?$_GET["totalRows"]:NULL;
$gifpay=!empty($_GET["ifpay"])?$_GET["ifpay"]:NULL;
$sprice=!empty($_GET["sprice"])?$_GET["sprice"]:NULL;
$eprice=!empty($_GET["eprice"])?$_GET["eprice"]:NULL;
$province=!empty($_GET["province"])?$_GET['province']:NULL;
$orderby=!empty($_GET["orderby"])?$_GET['orderby']:NULL;
//----------------------------------获取自定义字段搜索项
$sql="select catInfo,catName,catItem from ".EXTENDFILE." where isSearch=1 and catid='$id'";
$db->query($sql);
$catfile=$db->getRows();
foreach($catfile as $fkey=>$v)
{
	$catField=explode(',',$v['catItem']);
	foreach($catField as $skey=>$sv)
	{
		$catField[$skey]=explode('|',$sv);
	}
	$catfile[$fkey]['catItem']=$catField;
}
$tpl->assign("catfile",$catfile);
//----------------------------------
if(is_numeric($id))
{
	$cat=readCat($id);
	if(isset($cat["pcat"]["catid"]))
		$pcat="<a href='$config[weburl]/?m=product&s=product_list&id=".$cat["pcat"]["catid"]."'>".$cat["pcat"]["cat"]."</a> &raquo; ";
	$guide=$pcat.$cat["cat"];
	$tpl->assign("guide",$guide);

	$cid=strlen($id);
	$scl=" and left(a.catid,$cid)='$id' ";
	
	if(!empty($cat['brand']))
	{
		$sql="select * from ".BRAND." where id in ( $cat[brand] ) order by nums asc ";
		$db->query($sql);
		$re=$db->getRows();
		$tpl->assign("brand",$re);
	}
	
}
if(!empty($_GET['id']))
	$scl.=" and LOCATE(".intval(trim($_GET['id'])).",a.catid)=1 ";//按类别搜索
if(!empty($key))
	$scl.=" and ( a.keywords like '%$key%' or a.pname like '%$key%' )";
if(!empty($province))
	$scl.= " and a.province='$province' ";
if(!empty($trade_type))
	$scl.= " and a.trade_type='$trade_type' ";
if(!empty($_GET['brand']))
	$scl.= " and a.pp='".$_GET['brand']."' ";
if($gifpay)
	$scl.=" and a.ifpay='$gifpay' ";
if($sprice)
	$scl.=" and a.price>='$sprice' ";
if($eprice)
	$scl.=" and a.price<='$eprice' ";
	
if($orderby==1)
	$scl.=" order by a.ifpay desc";
elseif($orderby==2)
	$scl.=" order by a.uptime desc";	
elseif($orderby==3)
	$scl.=" order by a.uptime asc";
elseif($orderby==4)
	$scl.=" order by a.price asc";
elseif($orderby==5)
	$scl.=" order by a.price desc";
elseif($orderby==6)
	$scl.=" order by a.sell_amount desc";
else
	$scl.=" order by a.rank desc,a.ifpay desc, a.uptime desc";
//--------------------------------------------------
include_once("includes/page_utf_class.php");
$page = new Page;
$page->url=$config['weburl'].'/';
$page->listRows=12;
$sql="SELECT a.*,b.country,b.company 
FROM ".PRO." a left join ".USER." b on a.userid=b.userid WHERE a.statu>0 $scl";
if (!$page->__get('totalRows'))
{
	$db->query($sql);
	$page->totalRows =$db->num_rows();
}
$sql.=" limit ".$page->firstRow.", 12";
//--------------------------------------------------
$db->query($sql);
$prol=$db->getRows();

include_once($config['webroot']."/module/product/includes/plugin_pro_class.php");
$pro = new pro();
foreach($prol as $keys=>$v)
{
	$ifpay=!empty($v['ifpay'])?$v['ifpay']:1;
	if(!empty($group[$ifpay]['minilogo']))
		$prol[$keys]['user_type']="<img src='".$group[$ifpay]['minilogo']."' alt='".$group[$ifpay]['name']."' >";
	else
		$prol[$keys]['user_type']="[".$group[$ifpay]['name']."]";
	if($prol[$keys]['pic']!=''){
		$pic = $pro->pic_save_path.$pro->get_cover_img($prol[$keys]['pic']);
		$prol[$keys]['img'] = $pic;
		$prol[$keys]['big_img'] = substr($pic,0,strrpos($pic,'/')+1).'big_'.substr($pic,strrpos($pic,'/')+1);
	}else{
		$prol[$keys]['img'] = '/image/default/nopic.gif';
		$prol[$keys]['big_img'] ='/image/default/nopic.gif';		
	}
}
$infoList['list']=$prol;
$infoList['page']=$page->prompt();
$tpl->assign("info",$infoList);
unset($infoList);

$tpl->assign("province",get_province($province));
$tpl->assign("queryurl",$queryurl="&sprice=$sprice&eprice=$eprice&key=$key&id=$id&ifpay=$gifpay&trade_type=$trade_type");

$trade_type=explode('|',$module_product_config['trade_type']);
$tpl->assign("trade_type",$trade_type);

$tpl->assign("group",$group);
$tpl->assign("num",$page->totalRows);
$tpl->assign("subcat",is_numeric($id)?readsubcat($id,NULL,'all'):null);
include_once("footer.php");
//=====================================================
$out=tplfetch("product_list.htm",$flag,true);
?>